import json
import unittest

import app
from api.login import LoginAPI
from parameterized import parameterized

from utiles import commin_assert


def build_login_data():
    list_data = []
    file = "D:/AE/IHRM/data/login.json"
    with open(file, encoding="utf-8") as f:
        json_data = json.load(f)
        for case_data in json_data:
            login_data = case_data.get("login_data")
            status_code = case_data.get("status_code")
            success = case_data.get("success")
            code = case_data.get("code")
            message = case_data.get("message")
            list_data.append((login_data, status_code, success, code, message))
    return list_data


class TestLogin(unittest.TestCase):

    def setUp(self):
        self.login_api = LoginAPI()

    def tearDown(self):
        pass
    @parameterized.expand(build_login_data)
    def test01_Login001(self, login_data, status_code, success, code, message):
        response = self.login_api.login(login_data)
        print(response.json())
        if success:
            app.TOKEN ="Bearer " + response.json().get("data")
            app.headers_data["Authorization"] = app.TOKEN

        # self.assertEqual(status_code, response.status_code)
        # self.assertEqual(success, response.json().get("success"))
        # self.assertEqual(code,  response.json().get("code"))
        # self.assertIn(message, response.json().get("message"))
        commin_assert(self, response, status_code, success, code, message)
